package com.hn.zhijian.base.data.common;

import com.hn.zhijian.base.common.ApplicationBeanUtil;
import com.hn.zhijian.utils.Utils;
import org.springframework.stereotype.Component;
import java.util.Map;

/**
 * @program: carl-main
 * @description: 加载所有数据源
 * @author: carl
 * @create: 2019-11-17 19:24
 **/
public class DBLoadSource {

    private static DBLoadSource dbLoadSource;

    private DBLoadSource() {

    }

    /**
     * 实例化
     *
     * @return
     */
    public static DBLoadSource instance() {
        if (Utils.isEmpty(dbLoadSource)) {
            dbLoadSource = new DBLoadSource();
        }
        return dbLoadSource;
    }


    //初始化方法
    public Map<String, IDataSource> getDataSources() {
        return ApplicationBeanUtil.getApplicationContext().getBeansOfType(IDataSource.class);
    }

    public Object getDataSource(String beanName){
        return ApplicationBeanUtil.getApplicationContext().getBean(beanName);
    }
}
